/**
 * 赛博侦探游戏 - 调查场景
 * 实现赛博朋克风格的调查界面，包含对话系统、嫌疑人选择、线索面板和计时器
 */

import Phaser from 'phaser';
import { useGameState } from '../GameState';
import { SuspectData, ClueData } from '../../types/game';

export class InvestigationScene extends Phaser.Scene {
  private suspects: SuspectData[] = [];
  private currentSuspect: string = '';
  private chatContainer!: Phaser.GameObjects.Container;
  private cluePanel!: Phaser.GameObjects.Container;
  private timerText!: Phaser.GameObjects.Text;
  private timeRemaining: number = 180;
  private inputBox!: Phaser.GameObjects.DOMElement;
  private suspectCards: Map<string, Phaser.GameObjects.Container> = new Map();
  private chatMessages: Phaser.GameObjects.Container[] = [];
  private clueItems: Phaser.GameObjects.Container[] = [];
  
  constructor() {
    super({ key: 'Investigation' });
  }

  /**
   * 预加载调查场景资源
   */
  preload() {
    // 创建简单的像素纹理用于粒子效果
    this.load.image('particle', '');
  }

  /**
   * 初始化调查场景
   */
  create(data?: { caseData?: any; suspects?: SuspectData[] }) {
    const gameState = useGameState.getState();
    this.suspects = data?.suspects || gameState.suspects;
    
    // 创建赛博朋克风格背景
    this.createBackground();
    
    // 创建UI界面
    this.createChatInterface();
    this.createSuspectSelection();
    this.createCluePanel();
    this.createTimer();
    this.createControlButtons();
    
    // 启动计时器
    this.startTimer();
    
    // 显示案件信息
    this.displayCaseInfo();
    
    // 设置键盘事件
    this.setupKeyboardEvents();
  }

  /**
   * 创建赛博朋克风格背景
   */
  private createBackground() {
    const { width, height } = this.scale;
    
    // 渐变背景
    const bg = this.add.graphics();
    bg.fillGradientStyle(0x0a0a0a, 0x1a1a2e, 0x16213e, 0x0f3460);
    bg.fillRect(0, 0, width, height);
    
    // 网格效果
    this.createGridEffect();
    
    // 粒子效果
    this.createParticleSystem();
    
    // 霓虹边框
    this.createNeonBorder();
  }

  /**
   * 创建网格效果
   */
  private createGridEffect() {
    const { width, height } = this.scale;
    const gridSize = 40;
    
    const grid = this.add.graphics();
    grid.lineStyle(1, 0x00FFFF, 0.1);
    
    // 垂直线
    for (let x = 0; x <= width; x += gridSize) {
      grid.moveTo(x, 0);
      grid.lineTo(x, height);
    }
    
    // 水平线
    for (let y = 0; y <= height; y += gridSize) {
      grid.moveTo(0, y);
      grid.lineTo(width, y);
    }
    
    grid.strokePath();
  }

  /**
   * 创建粒子系统
   */
  private createParticleSystem() {
    const { width, height } = this.scale;
    
    // 创建粒子发射器
    const particles = this.add.particles(0, 0, 'particle', {
      x: { min: 0, max: width },
      y: { min: -10, max: -5 },
      speedY: { min: 10, max: 30 },
      scale: { min: 0.1, max: 0.2 },
      alpha: { start: 0.6, end: 0 },
      lifespan: 4000,
      tint: [0x00FFFF, 0xFF00FF, 0x39FF14],
      frequency: 200
    });
  }

  /**
   * 创建霓虹边框
   */
  private createNeonBorder() {
    const { width, height } = this.scale;
    
    const border = this.add.graphics();
    border.lineStyle(2, 0x00FFFF, 0.8);
    border.strokeRect(5, 5, width - 10, height - 10);
  }

  /**
   * 创建对话界面
   */
  private createChatInterface() {
    const { width, height } = this.scale;
    
    // 对话区域背景
    const chatBg = this.add.graphics();
    chatBg.fillStyle(0x000000, 0.7);
    chatBg.strokeStyle(0x00FFFF, 2);
    chatBg.fillRoundedRect(20, 80, width * 0.55, height * 0.6, 10);
    chatBg.strokeRoundedRect(20, 80, width * 0.55, height * 0.6, 10);
    
    // 聊天消息容器
    this.chatContainer = this.add.container(30, 90);
    
    // 输入框区域
    this.createInputBox();
    
    // 标题
    this.add.text(30, 50, '调查对话', {
      fontSize: '20px',
      color: '#00FFFF',
      fontFamily: 'Arial, sans-serif'
    });
  }

  /**
   * 创建输入框
   */
  private createInputBox() {
    const { width, height } = this.scale;
    
    // 输入框背景
    const inputBg = this.add.graphics();
    inputBg.fillStyle(0x1a1a2e, 0.9);
    inputBg.strokeStyle(0xFF00FF, 2);
    inputBg.fillRoundedRect(20, height * 0.75, width * 0.55, 50, 5);
    inputBg.strokeRoundedRect(20, height * 0.75, width * 0.55, 50, 5);
    
    // 创建HTML输入框
    const inputElement = this.add.dom(width * 0.275, height * 0.775, 'input', {
      type: 'text',
      placeholder: '输入你的问题...',
      style: `
        width: ${width * 0.45}px;
        height: 40px;
        background: transparent;
        border: none;
        color: #FFFFFF;
        font-size: 16px;
        padding: 0 10px;
        outline: none;
      `
    });
    
    // 发送按钮
    const sendButton = this.createButton(width * 0.6, height * 0.775, '发送', () => {
      const input = inputElement.node as HTMLInputElement;
      const question = input.value.trim();
      if (question && this.currentSuspect) {
        this.askQuestion(question);
        input.value = '';
      }
    });
    
    // 回车发送
    inputElement.addListener('keydown');
    inputElement.on('keydown', (event: KeyboardEvent) => {
      if (event.key === 'Enter') {
        const input = inputElement.node as HTMLInputElement;
        const question = input.value.trim();
        if (question && this.currentSuspect) {
          this.askQuestion(question);
          input.value = '';
        }
      }
    });
    
    this.inputBox = inputElement;
  }

  /**
   * 创建嫌疑人选择界面
   */
  private createSuspectSelection() {
    const { width, height } = this.scale;
    const startX = width * 0.6;
    const startY = 80;
    const spacing = 100;
    
    // 标题
    this.add.text(startX, 50, '嫌疑人', {
      fontSize: '20px',
      color: '#00FFFF',
      fontFamily: 'Arial, sans-serif'
    });
    
    this.suspects.forEach((suspect, index) => {
      const x = startX;
      const y = startY + (index * spacing);
      
      // 创建嫌疑人卡片
      const card = this.createSuspectCard(suspect, x, y);
      this.suspectCards.set(suspect.id, card);
      
      // 点击事件
      card.setSize(200, 80);
      card.setInteractive()
        .on('pointerdown', () => this.selectSuspect(suspect.id))
        .on('pointerover', () => this.highlightSuspect(card))
        .on('pointerout', () => this.unhighlightSuspect(card));
    });
  }

  /**
   * 创建嫌疑人卡片
   */
  private createSuspectCard(suspect: SuspectData, x: number, y: number): Phaser.GameObjects.Container {
    const container = this.add.container(x, y);
    
    // 卡片背景
    const cardBg = this.add.graphics();
    cardBg.fillStyle(0x1a1a2e, 0.9);
    cardBg.strokeStyle(0xFF00FF, 1);
    cardBg.fillRoundedRect(-100, -40, 200, 80, 8);
    cardBg.strokeRoundedRect(-100, -40, 200, 80, 8);
    
    // 头像
    const avatar = this.add.circle(-70, 0, 20, 0x00FFFF);
    
    // 姓名
    const nameText = this.add.text(-40, -15, suspect.name, {
      fontSize: '16px',
      color: '#FFFFFF',
      fontFamily: 'Arial, sans-serif'
    });
    
    // 职业/背景
    const backgroundText = this.add.text(-40, 5, suspect.background, {
      fontSize: '12px',
      color: '#CCCCCC',
      fontFamily: 'Arial, sans-serif'
    });
    
    // 状态指示器
    const statusIndicator = this.add.circle(80, -30, 6, 0x39FF14);
    
    container.add([cardBg, avatar, nameText, backgroundText, statusIndicator]);
    
    return container;
  }

  /**
   * 创建线索面板
   */
  private createCluePanel() {
    const { width, height } = this.scale;
    const panelX = width * 0.6;
    const panelY = height * 0.5;
    const panelWidth = width * 0.35;
    const panelHeight = height * 0.4;
    
    // 线索面板背景
    const clueBg = this.add.graphics();
    clueBg.fillStyle(0x000000, 0.7);
    clueBg.strokeStyle(0x39FF14, 2);
    clueBg.fillRoundedRect(panelX, panelY, panelWidth, panelHeight, 10);
    clueBg.strokeRoundedRect(panelX, panelY, panelWidth, panelHeight, 10);
    
    // 标题
    this.add.text(panelX + 10, panelY - 30, '发现的线索', {
      fontSize: '18px',
      color: '#39FF14',
      fontFamily: 'Arial, sans-serif'
    });
    
    // 线索容器
    this.cluePanel = this.add.container(panelX + 10, panelY + 10);
    
    // 显示初始线索
    this.displayInitialClues();
  }

  /**
   * 创建计时器
   */
  private createTimer() {
    const { width } = this.scale;
    
    // 计时器背景
    const timerBg = this.add.graphics();
    timerBg.fillStyle(0x000000, 0.8);
    timerBg.strokeStyle(0xFF0000, 2);
    timerBg.fillRoundedRect(width - 150, 10, 140, 50, 10);
    timerBg.strokeRoundedRect(width - 150, 10, 140, 50, 10);
    
    // 计时器文本
    this.timerText = this.add.text(width - 80, 35, '03:00', {
      fontSize: '24px',
      color: '#FFFFFF',
      fontFamily: 'Arial, sans-serif'
    }).setOrigin(0.5);
    
    // 标签
    this.add.text(width - 80, 15, '剩余时间', {
      fontSize: '12px',
      color: '#CCCCCC',
      fontFamily: 'Arial, sans-serif'
    }).setOrigin(0.5);
  }

  /**
   * 创建控制按钮
   */
  private createControlButtons() {
    const { width, height } = this.scale;
    
    // 提交推理按钮
    this.createButton(width - 150, height - 60, '提交推理', () => {
      this.submitSolution();
    });
    
    // 返回主菜单按钮
    this.createButton(width - 300, height - 60, '返回主菜单', () => {
      this.scene.start('MainMenu');
    });
  }

  /**
   * 创建按钮
   */
  private createButton(x: number, y: number, text: string, callback: () => void): Phaser.GameObjects.Container {
    const container = this.add.container(x, y);
    
    // 按钮背景
    const bg = this.add.graphics();
    bg.fillStyle(0x1a1a2e, 0.8);
    bg.strokeStyle(0x00FFFF, 2);
    bg.fillRoundedRect(-60, -20, 120, 40, 8);
    bg.strokeRoundedRect(-60, -20, 120, 40, 8);
    
    // 按钮文字
    const buttonText = this.add.text(0, 0, text, {
      fontSize: '16px',
      color: '#FFFFFF',
      fontFamily: 'Arial, sans-serif'
    }).setOrigin(0.5);
    
    container.add([bg, buttonText]);
    
    // 交互事件
    container.setSize(120, 40);
    container.setInteractive()
      .on('pointerover', () => {
        bg.clear();
        bg.fillStyle(0x00FFFF, 0.2);
        bg.strokeStyle(0xFF00FF, 3);
        bg.fillRoundedRect(-60, -20, 120, 40, 8);
        bg.strokeRoundedRect(-60, -20, 120, 40, 8);
        buttonText.setColor('#00FFFF');
      })
      .on('pointerout', () => {
        bg.clear();
        bg.fillStyle(0x1a1a2e, 0.8);
        bg.strokeStyle(0x00FFFF, 2);
        bg.fillRoundedRect(-60, -20, 120, 40, 8);
        bg.strokeRoundedRect(-60, -20, 120, 40, 8);
        buttonText.setColor('#FFFFFF');
      })
      .on('pointerdown', () => {
        // 按钮点击动画
        this.tweens.add({
          targets: container,
          scaleX: 0.95,
          scaleY: 0.95,
          duration: 100,
          yoyo: true,
          onComplete: callback
        });
      });
    
    return container;
  }

  /**
   * 选择嫌疑人进行对话
   */
  private selectSuspect(suspectId: string) {
    this.currentSuspect = suspectId;
    
    // 更新UI显示当前选中的嫌疑人
    this.updateSuspectSelection(suspectId);
    
    // 添加选择提示消息
    const suspect = this.suspects.find(s => s.id === suspectId);
    if (suspect) {
      this.addChatMessage('system', `已选择与 ${suspect.name} 对话`);
    }
  }

  /**
   * 更新嫌疑人选择状态
   */
  private updateSuspectSelection(selectedId: string) {
    this.suspectCards.forEach((card, suspectId) => {
      const bg = card.list[0] as Phaser.GameObjects.Graphics;
      if (suspectId === selectedId) {
        // 选中状态
        bg.clear();
        bg.fillStyle(0x00FFFF, 0.3);
        bg.strokeStyle(0x00FFFF, 3);
        bg.fillRoundedRect(-100, -40, 200, 80, 8);
        bg.strokeRoundedRect(-100, -40, 200, 80, 8);
      } else {
        // 未选中状态
        bg.clear();
        bg.fillStyle(0x1a1a2e, 0.9);
        bg.strokeStyle(0xFF00FF, 1);
        bg.fillRoundedRect(-100, -40, 200, 80, 8);
        bg.strokeRoundedRect(-100, -40, 200, 80, 8);
      }
    });
  }

  /**
   * 高亮嫌疑人卡片
   */
  private highlightSuspect(card: Phaser.GameObjects.Container) {
    if (card.list[0] instanceof Phaser.GameObjects.Graphics) {
      const bg = card.list[0] as Phaser.GameObjects.Graphics;
      bg.clear();
      bg.fillStyle(0xFF00FF, 0.2);
      bg.strokeStyle(0xFF00FF, 2);
      bg.fillRoundedRect(-100, -40, 200, 80, 8);
      bg.strokeRoundedRect(-100, -40, 200, 80, 8);
    }
  }

  /**
   * 取消高亮嫌疑人卡片
   */
  private unhighlightSuspect(card: Phaser.GameObjects.Container) {
    // 恢复原始状态，需要检查是否为当前选中的嫌疑人
    // 这里简化处理，实际应该根据选中状态来决定样式
    if (card.list[0] instanceof Phaser.GameObjects.Graphics) {
      const bg = card.list[0] as Phaser.GameObjects.Graphics;
      bg.clear();
      bg.fillStyle(0x1a1a2e, 0.9);
      bg.strokeStyle(0xFF00FF, 1);
      bg.fillRoundedRect(-100, -40, 200, 80, 8);
      bg.strokeRoundedRect(-100, -40, 200, 80, 8);
    }
  }

  /**
   * 发送问题给AI Agent
   */
  private async askQuestion(question: string) {
    if (!this.currentSuspect || !question.trim()) {
      this.addChatMessage('system', '请先选择一个嫌疑人，然后输入问题');
      return;
    }
    
    // 显示玩家问题
    this.addChatMessage('player', question);
    
    // 显示加载状态
    const loadingMsg = this.addChatMessage('system', '正在思考...');
    
    try {
      // 调用游戏状态管理中的AI接口
      await useGameState.getState().askQuestion(question, this.currentSuspect);
      
      // 移除加载消息
      this.removeChatMessage(loadingMsg);
      
      // 获取最新的对话历史
      const conversations = useGameState.getState().conversationHistory;
      const latestConversation = conversations[conversations.length - 1];
      
      if (latestConversation) {
        // 显示AI回答
        const suspect = this.suspects.find(s => s.id === this.currentSuspect);
        this.addChatMessage('suspect', `${suspect?.name}: ${latestConversation.response}`);
        
        // 检查是否有新线索
        this.checkForNewClues();
      }
      
    } catch (error) {
      this.removeChatMessage(loadingMsg);
      this.addChatMessage('system', '对话出现错误，请重试');
      console.error('AI对话错误:', error);
    }
  }

  /**
   * 添加聊天消息
   */
  private addChatMessage(sender: string, message: string): Phaser.GameObjects.Container {
    const messageY = this.chatMessages.length * 35;
    const messageContainer = this.add.container(0, messageY);
    
    // 消息背景
    const msgBg = this.add.graphics();
    const isPlayer = sender === 'player';
    const isSystem = sender === 'system';
    let bgColor = 0xFF00FF; // 默认嫌疑人颜色
    
    if (isPlayer) {
      bgColor = 0x00FFFF;
    } else if (isSystem) {
      bgColor = 0x39FF14;
    }
    
    msgBg.fillStyle(bgColor, 0.2);
    msgBg.fillRoundedRect(0, 0, 480, 30, 5);
    
    // 消息文本
    const msgText = this.add.text(10, 5, message, {
      fontSize: '14px',
      color: '#FFFFFF',
      fontFamily: 'Arial, sans-serif',
      wordWrap: { width: 460 }
    });
    
    messageContainer.add([msgBg, msgText]);
    this.chatContainer.add(messageContainer);
    this.chatMessages.push(messageContainer);
    
    // 自动滚动
    this.scrollChatToBottom();
    
    return messageContainer;
  }

  /**
   * 移除聊天消息
   */
  private removeChatMessage(messageContainer: Phaser.GameObjects.Container) {
    const index = this.chatMessages.indexOf(messageContainer);
    if (index > -1) {
      this.chatMessages.splice(index, 1);
      messageContainer.destroy();
      
      // 重新排列剩余消息
      this.chatMessages.forEach((msg, i) => {
        msg.setY(i * 35);
      });
    }
  }

  /**
   * 滚动聊天到底部
   */
  private scrollChatToBottom() {
    const maxVisibleMessages = 12;
    if (this.chatMessages.length > maxVisibleMessages) {
      const scrollOffset = (this.chatMessages.length - maxVisibleMessages) * 35;
      this.chatContainer.setY(90 - scrollOffset);
    }
  }

  /**
   * 显示案件信息
   */
  private displayCaseInfo() {
    const gameState = useGameState.getState();
    const currentCase = gameState.currentCase;
    
    if (currentCase) {
      this.addChatMessage('system', `案件：${currentCase.title}`);
      this.addChatMessage('system', `地点：${currentCase.location}`);
      this.addChatMessage('system', `时间：${currentCase.timeOfCrime}`);
      this.addChatMessage('system', '开始调查吧！选择一个嫌疑人进行询问。');
    }
  }

  /**
   * 显示初始线索
   */
  private displayInitialClues() {
    const gameState = useGameState.getState();
    const clues = gameState.discoveredClues;
    
    clues.forEach((clue, index) => {
      this.addClueToPanel(clue, index);
    });
  }

  /**
   * 添加线索到面板
   */
  private addClueToPanel(clue: ClueData, index?: number) {
    const clueIndex = index !== undefined ? index : this.clueItems.length;
    const clueY = clueIndex * 60;
    
    const clueContainer = this.add.container(0, clueY);
    
    // 线索背景
    const clueBg = this.add.graphics();
    clueBg.fillStyle(0x39FF14, 0.1);
    clueBg.strokeStyle(0x39FF14, 1);
    clueBg.fillRoundedRect(0, 0, 300, 50, 5);
    clueBg.strokeRoundedRect(0, 0, 300, 50, 5);
    
    // 线索类型图标
    const typeIcon = this.add.circle(20, 25, 8, this.getClueTypeColor(clue.type));
    
    // 线索描述
    const clueText = this.add.text(35, 10, clue.description, {
      fontSize: '12px',
      color: '#FFFFFF',
      fontFamily: 'Arial, sans-serif',
      wordWrap: { width: 250 }
    });
    
    // 重要性指示器
    const importance = '★'.repeat(clue.importance);
    const importanceText = this.add.text(35, 30, importance, {
      fontSize: '14px',
      color: '#FFD700',
      fontFamily: 'Arial, sans-serif'
    });
    
    clueContainer.add([clueBg, typeIcon, clueText, importanceText]);
    this.cluePanel.add(clueContainer);
    this.clueItems.push(clueContainer);
  }

  /**
   * 获取线索类型颜色
   */
  private getClueTypeColor(type: string): number {
    switch (type) {
      case 'physical': return 0xFF0000; // 红色 - 物理证据
      case 'testimony': return 0x0000FF; // 蓝色 - 证词
      case 'circumstantial': return 0xFFFF00; // 黄色 - 间接证据
      case 'digital': return 0x00FF00; // 绿色 - 数字证据
      default: return 0xFFFFFF; // 白色 - 其他
    }
  }

  /**
   * 检查新线索
   */
  private checkForNewClues() {
    const gameState = useGameState.getState();
    const currentClues = gameState.discoveredClues;
    
    // 如果发现了新线索，添加到面板
    if (currentClues.length > this.clueItems.length) {
      const newClues = currentClues.slice(this.clueItems.length);
      newClues.forEach(clue => {
        this.addClueToPanel(clue);
        this.addChatMessage('system', `发现新线索：${clue.description}`);
      });
    }
  }

  /**
   * 启动游戏计时器
   */
  private startTimer() {
    this.time.addEvent({
      delay: 1000,
      callback: () => {
        this.timeRemaining--;
        this.updateTimerDisplay();
        
        // 更新游戏状态中的时间
        useGameState.getState().updateTimeRemaining(this.timeRemaining);
        
        if (this.timeRemaining <= 0) {
          this.endInvestigation();
        }
      },
      loop: true
    });
  }

  /**
   * 更新计时器显示
   */
  private updateTimerDisplay() {
    const minutes = Math.floor(this.timeRemaining / 60);
    const seconds = this.timeRemaining % 60;
    const timeStr = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
    
    this.timerText.setText(timeStr);
    
    // 时间紧急时改变颜色和效果
    if (this.timeRemaining < 30) {
      this.timerText.setColor('#FF0000');
      this.timerText.setScale(1.2);
      
      // 添加闪烁效果
      this.tweens.add({
        targets: this.timerText,
        alpha: 0.3,
        duration: 500,
        yoyo: true,
        repeat: -1
      });
    } else if (this.timeRemaining < 60) {
      this.timerText.setColor('#FFFF00');
      this.timerText.setScale(1.1);
    }
  }

  /**
   * 提交推理结果
   */
  private submitSolution() {
    // 创建推理提交对话框
    const { width, height } = this.scale;
    
    // 遮罩层
    const overlay = this.add.graphics();
    overlay.fillStyle(0x000000, 0.7);
    overlay.fillRect(0, 0, width, height);
    
    // 对话框背景
    const dialogBg = this.add.graphics();
    dialogBg.fillStyle(0x1a1a2e, 0.95);
    dialogBg.strokeStyle(0x00FFFF, 3);
    dialogBg.fillRoundedRect(width * 0.2, height * 0.3, width * 0.6, height * 0.4, 15);
    dialogBg.strokeRoundedRect(width * 0.2, height * 0.3, width * 0.6, height * 0.4, 15);
    
    // 标题
    const title = this.add.text(width * 0.5, height * 0.35, '提交你的推理', {
      fontSize: '24px',
      color: '#00FFFF',
      fontFamily: 'Arial, sans-serif'
    }).setOrigin(0.5);
    
    // 输入框
    const solutionInput = this.add.dom(width * 0.5, height * 0.5, 'textarea', {
      placeholder: '请输入你认为的凶手和作案动机...',
      style: `
        width: ${width * 0.5}px;
        height: 100px;
        background: rgba(26, 26, 46, 0.8);
        border: 2px solid #FF00FF;
        color: #FFFFFF;
        font-size: 16px;
        padding: 10px;
        border-radius: 8px;
        resize: none;
        outline: none;
      `
    });
    
    // 确认按钮
    const confirmButton = this.createButton(width * 0.4, height * 0.6, '确认提交', () => {
      const textarea = solutionInput.node as HTMLTextAreaElement;
      const solution = textarea.value.trim();
      if (solution) {
        useGameState.getState().submitSolution(solution);
        this.endInvestigation();
      }
    });
    
    // 取消按钮
    const cancelButton = this.createButton(width * 0.6, height * 0.6, '继续调查', () => {
      overlay.destroy();
      dialogBg.destroy();
      title.destroy();
      solutionInput.destroy();
      confirmButton.destroy();
      cancelButton.destroy();
    });
  }

  /**
   * 结束调查，进入结案阶段
   */
  private endInvestigation() {
    // 保存调查结果
    const gameSession = useGameState.getState().getCurrentSession();
    
    // 淡出效果
    this.cameras.main.fadeOut(1000, 0, 0, 0);
    
    this.cameras.main.once('camerafadeoutcomplete', () => {
      // 切换到结案场景（暂时返回主菜单）
      this.scene.start('MainMenu');
    });
  }

  /**
   * 设置键盘事件
   */
  private setupKeyboardEvents() {
    // ESC键返回主菜单
    this.input.keyboard?.on('keydown-ESC', () => {
      this.scene.start('MainMenu');
    });
    
    // 数字键快速选择嫌疑人
    for (let i = 1; i <= this.suspects.length; i++) {
      this.input.keyboard?.on(`keydown-${i}`, () => {
        if (this.suspects[i - 1]) {
          this.selectSuspect(this.suspects[i - 1].id);
        }
      });
    }
  }

  /**
   * 场景更新
   */
  update() {
    // 可以在这里添加动画更新逻辑
  }
}